<template>
    <div class="write-review-page">
      <van-field v-model="review.title" label="标题" placeholder="请输入评价标题" clearable class="field-style" />
      <van-field v-model="review.content" label="内容" type="textarea" placeholder="请输入评价内容" clearable class="field-style" />
      <van-rate v-model="review.rating" class="rate-style" />
      <van-button type="primary" @click="submitReview">提交评价</van-button>
    </div>
</template>
  
<script setup>
import { ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { showConfirmDialog } from 'vant';
const route=useRoute()
const router=useRouter()
const order_Id = route.params.id;

const review = ref({
  title: '',
  content: '',
  rating: 0,
});

import { reviewOrder } from '@/api';
import { showToast } from 'vant';
//提交评价
const submitReview = async() => {
  showConfirmDialog({
    title: '确认评价',
    message: '您要提交评价吗？',
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    onConfirm: async() => {
      //确认评价
      const content = review.value.content
      const rating = review.value.rating
      const orderId=order_Id
      if (!content) {
        showToast('评价不能为空');
        return;
      }
      const data = await reviewOrder({
        review:content,
        reviewStar:rating,
        orderId
      })
      setTimeout(()=>{
        router.back()
      },1000)
    },
    onCancel: () => {
      // 取消提交逻辑
      console.log('已取消');
    },
  });
};
</script>

<style scoped>
.write-review-page {
  padding: 20px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  max-width: 400px;
  margin: 0 auto;
}

.field-style {
  margin-bottom: 10px;
  border-radius: 4px;
  border: 1px solid #e2e2e2;
  padding: 8px;
}

.rate-style {
  margin-bottom: 20px;
}

.van-button {
  width: 100%;
  padding: 10px;
  border-radius: 4px;
  background-color: #007bff;
  color: #fff;
  border: none;
  text-align: center;
}
</style>
